<?php
/**
 * 充值审核逻辑模块
 * User：LLW
 * Date：2020-04-08
 * Time：11：57
 */

namespace app\caidongweb\model;

class CashTypeModel extends BaseModel
{
    protected $table = 'cd_cash_type';

    public function getList()
    {
        $where = [];
        $sta = strtotime(input('start'));
        $end = strtotime(input('end'));
        if($sta && $end){
            $where['ct_time'] = array('between',"$sta,$end");
        }
        input('key') ? $where[input('city')] = input('key') : false;
        $list = $this->where($where)->order('ct_time asc')
            ->paginate(20,false,['query'=>request()->param()]);
        return $list;
    }

    public function getState()
    {
        $id = input('id');
        $find = $this->where('ct_id',$id)->find();
        if(empty($find)){
            return $this->returnData(-1,'充值信息未找到');
        }
        if($find['ct_state'] != 0){
            return $this->returnData(-1,'充值信息已处理');
        }
        $res = $this->where('ct_id',$id)->setField('ct_state',1);
        if($res){
            accountMoneyLog($find['ct_uid'],$find['ct_money'],'充值到余额');
            return $this->returnData(1,'处理成功');
        }else{
            return $this->returnData(-1,'处理失败');
        }
    }
}